package com.wits.qso.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import net.sf.json.JSONObject;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import com.wits.platform.entity.BaseEntity;

/**
 * @author Ethan Lee
 */

@Entity
@Table(name="qso_list")
public class CList extends BaseEntity
{
	private String id = null;
	private String name = null;
	private CList fatherId = null;
	
	public CList() { super(); }
	
	@Id
	@GenericGenerator(name = "idGen", 
					strategy = "com.wits.platform.common.id.generator.IDGenerator",
					parameters={ 
								@Parameter(name = "segment_value", value = "QSO_LIST_ID"), 
								@Parameter(name="table_name",value="wits_id_generator"),
								@Parameter(name="value_column_name",value="gen_value"),
								@Parameter(name="segment_column_name",value="gen_name"),
								@Parameter(name="segment_value_length",value="5"),
								@Parameter(name="sq_format",value="%03d"), 
								@Parameter(name="sq_prefix",value="LST") 
					})
	@GeneratedValue(generator = "idGen")
	@Column(name = "lst_id", nullable = false, insertable = true, updatable = false, length = 10)
	public String getId() {
		return id;
	}

	@Column(name="lst_name", nullable = false, length = 50)
	public String getName() {
		return name;
	}

	@ManyToOne
	@JoinColumn(name = "lst_father_id")
	public CList getFatherId() {
		return fatherId;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setFatherId(CList fatherId) {
		this.fatherId = fatherId;
	}

	@Override
	public String display() {
		return null;
	}
	
	@Override
	public String toString(){
		return "{\"id\":\"" + this.id 
				+ "\",\"fatherName\":\"" + (null != fatherId ? this.fatherId.name : "")
				+ "\",\"name\":\""+ this.name
				+ "\"}";
	}
}
